﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace IndyMosaic.Models.Web
{
    public class NewsItemRepository : INewsItemRepository
    {
        WebDataContext context = new WebDataContext();

        #region INewsItemRepository Members

        public List<NewsItem> GetNewsItemsForToday()
        {
            return GetNewsItems(DateTime.Today);
        }

        public List<NewsItem> GetNewsItems(DateTime date)
        {
            List<NewsItem> newsItems = new List<NewsItem>();

            return context.NewsItems.Where(ni => ni.ExpirationDate > date).ToList();
        }
        public List<NewsItem> GetAll()
        {
            return context.NewsItems.OrderByDescending(ni => ni.ExpirationDate).ToList();
        }

        public NewsItem GetById(int id)
        {
            return context.NewsItems.Where(ni => ni.ID == id).FirstOrDefault();
        }

        public void Save()
        {
            context.SubmitChanges();
        }
        #endregion
    }
}